<template>
  <div class="app-container">

    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-input
        v-model="listQuery.goodsSn"
        clearable
        size="mini"
        class="filter-item"
        style="width: 200px;"
        placeholder="请输入商品编号"
      />
      <el-input
        v-model="listQuery.barCode"
        clearable
        size="mini"
        class="filter-item"
        style="width: 200px;"
        placeholder="请输入商品条形码"
      />
      <el-input
        v-model="listQuery.goodsName"
        clearable
        size="mini"
        class="filter-item"
        style="width: 200px;"
        placeholder="请输入商品名称"
      />
      <el-button
        size="mini"
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
      >查找
      </el-button>

<!--      <el-button-->
<!--        size="mini"-->
<!--        class="filter-item"-->
<!--        type="primary"-->
<!--        icon="el-icon-search"-->
<!--        @click="handlePandian"-->
<!--      >期初盘点-->
<!--      </el-button>-->
    </div>

    <!-- 查询结果 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      size="small"
      element-loading-text="正在查询中。。。"
      border
      fit
      highlight-current-row
    >
      <el-table-column
        align="center"
        min-width="110"
        label="条形码"
        prop="barCode"
      />
      <el-table-column
        align="center"
        min-width="110"
        label="商品编号"
        prop="goodsSn"
      />
      <el-table-column
        align="center"
        min-width="200"
        label="名称"
        prop="goodsName"
      />

      <el-table-column
        align="center"
        property="picUrl"
        label="图片"
      >
        <template slot-scope="scope">
          <img
            :src="scope.row.picUrl"
            width="40"
          >
        </template>
      </el-table-column>

      <el-table-column
        align="center"
        label="商品规格"
        prop="specifications"
      />

      <el-table-column
        align="center"
        label="期初数量"
        prop="beginningNumber"
      />

      <el-table-column
        align="center"
        label="成本价"
        prop="costPrice"
      />

      <el-table-column
        align="center"
        label="成本合计"
        prop="costTotal"
      />

      <el-table-column
        align="center"
        label="供货商名称"
        prop="supplierName"
      />

      <el-table-column
        align="center"
        label="供货商电话"
        prop="supplierPhone"
      />

      <el-table-column
        align="center"
        label="赠品"
        prop="giftWare"
      >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.giftWare"
            active-color="#13ce66"
            inactive-color="#494949"
            :active-value="1"
            :inactive-value="0"
            :disabled="true"
          />
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />

    <el-tooltip
      placement="top"
      content="返回顶部"
    >
      <back-to-top :visibility-height="100"/>
    </el-tooltip>

  </div>
</template>

<script>
import BackToTop from '@/components/BackToTop'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import { getToken } from '@/utils/auth'
import { listBeginningInventory, updateBeginning } from "@/api/business/inventory"

export default {
  name: 'BeginningInventoryList',
  components: { BackToTop, Pagination },
  data() {
    return {
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
        goodsSn: '',
        productId: undefined,
        goodsName: undefined,
        sort: 'add_time',
        order: 'desc',
        barCode: ''
      }
    }
  },
  computed: {
    headers() {
      return {
        'X-Dts-Merchant-Token': getToken()
      }
    }
  },
  created() {
    this.handlePandian()
    this.getList()
  },
  methods: {
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    getList() {
      this.listLoading = true
      listBeginningInventory(this.listQuery).then(response => {
        this.list = response.data.data.items
        this.total = response.data.data.total
        this.isAdmin = response.data.data.isAdmin
        this.listLoading = false
      }).catch(() => {
        this.list = []
        this.total = 0
        this.listLoading = false
      })
    },
    handlePandian() {
      var data = {}
      updateBeginning(data).then(response => {
        this.getList()
      })
    }
  }
}
</script>

<style>
.el-dialog {
  width: 60%;
}

.table-expand {
  font-size: 0;
}

.table-expand label {
  width: 100px;
  color: #99a9bf;
}

.table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
}

.gallery {
  width: 80px;
  margin-right: 10px;
}

.htmlSpan {
  white-space: pre-wrap;
  word-break: break-all;
}
</style>
